package homelesspartners.client.widgets;

import homelesspartners.client.ServerFacade;
import homelesspartners.client.model.Shelter;
import homelesspartners.client.model.User;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class ShelterWidget extends Composite {

	private Shelter shelter = null;
	private VerticalPanel panel = new VerticalPanel();

	public ShelterWidget(Shelter aShelter) {
		shelter = aShelter;
		Hyperlink shelterLink = new Hyperlink(shelter.getName(), "");
		shelterLink.addClickListener(new ClickListener() {

			public void onClick(Widget sender) {
				User.getInstance().setCurrentShelter(getShelter());
				if (!getShelter().isPagePopulated()) {
					ServerFacade.loadPageOfStories(getShelter(), 0);
				}
				GiftTabWidget.getInstance().showStories();
			}
		});
		panel.add(shelterLink);
		panel.add(new HTML("<b>" + shelter.getAddressText() + "</b>"));
		if (shelter.getWebsite() != null && shelter.getWebsite().length() != 0) {
			panel.add(new HTML("Website: " + shelter.getWebsite()));

		}
		panel.add(new HTML("<i>What do they do?</i> " + shelter.getWhatTheyDo()));
		if (shelter.getWhatTheyNeed() != null && shelter.getWhatTheyNeed().length() != 0) {
			panel.add(new HTML("<i>What do they need?</i> " + shelter.getWhatTheyNeed()));
		}
		panel.add(new HTML("<br />"));
		initWidget(panel);
	}

	public Shelter getShelter() {
		return shelter;
	}

}
